//
//  DragTableView.m
//  drawacartoon
//
//  Created by Ji Hu on 12-7-4.
//  Copyright (c) 2012年 爱辅导. All rights reserved.
//

#import "DragTableView.h"
#import "DragTableItemView.h"

@implementation DragTableView

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code
    }
    return self;
}

-(void)addItemImage:(UIImage*)image delegate:(id<ItemViewDelegate>)delegate withName:(NSString*)name{
    
    UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
    
    [self addItemView:imageView delegate:delegate withName:name];
    
    [imageView release];
}

-(void)addItemView:(UIView *)view delegate:(id<ItemViewDelegate>)delegate withName:(NSString*)name{
    
    DragTableItemView *item = [[DragTableItemView alloc] initWithView:view withFrame:CGRectMake(self.bounds.size.width/2, self.bounds.size.height/2, view.frame.size.width, view.frame.size.height)];
    item.delegate = delegate;
    item.name=name;
    [self addSubview:item];
    
    [item release];
    
}

-(void)expandSubviews{
    
    [UIView beginAnimations:@"expandsubview" context:NULL];
   
    [UIView setAnimationDuration:1];
    
    for (UIView *child in self.subviews) {
        int width = self.bounds.size.width/3*2;
        int height = self.bounds.size.height/3*2;
        int x = arc4random()%width;
        int y = arc4random()%height;
        [child setCenter:CGPointMake(x, y)];
    }
    
    [UIView commitAnimations];
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
    // Drawing code
}
*/

@end
